package pl.iachoo.ctl.tabory.ui;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import pl.iachoo.ctl.tabory.ui.actions.OpenViewEditorAction;
import pl.iachoo.ctl.tabory.ui.editors.compositions.CompositionEditor;
import pl.iachoo.ctl.tabory.ui.editors.stations.StationEditor;
import pl.iachoo.ctl.tabory.ui.editors.trips.TripEditor;
import pl.iachoo.ctl.tabory.ui.editors.users.UserEditor;
import pl.iachoo.ctl.tabory.ui.editors.vagons.VagonEditor;
import pl.iachoo.ctl.tabory.ui.properties.Messages;

/**
 * An action bar advisor is responsible for creating, adding, and disposing of
 * the actions added to a workbench window. Each window will be populated with
 * new actions.
 */
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

	private OpenViewEditorAction editVagonsAction;
	private OpenViewEditorAction editCompositionsAction;
	private OpenViewEditorAction editUsersAction;
	private OpenViewEditorAction editStationsAction;
	private OpenViewEditorAction editTripsAction;

	public ApplicationActionBarAdvisor(final IActionBarConfigurer configurer) {
		super(configurer);
	}

	@Override
	protected void makeActions(final IWorkbenchWindow window) {
		editVagonsAction = new OpenViewEditorAction(window,
				Messages.getString("menu.submenus.edit.vagon"), VagonEditor.ID);
		editCompositionsAction = new OpenViewEditorAction(window,
				Messages.getString("menu.submenus.edit.composition"),
				CompositionEditor.ID);
		editUsersAction = new OpenViewEditorAction(window,
				Messages.getString("menu.submenus.configuration.user"),
				UserEditor.ID);
		editStationsAction = new OpenViewEditorAction(window,
				Messages.getString("menu.submenus.edit.stations"),
				StationEditor.ID);
		editTripsAction = new OpenViewEditorAction(window,
				Messages.getString("menu.submenus.edit.trips"), TripEditor.ID);
		register(editVagonsAction);
		register(editCompositionsAction);
		register(editUsersAction);
		register(editStationsAction);
		register(editTripsAction);
	}

	@Override
	protected void fillMenuBar(final IMenuManager menuBar) {
		final MenuManager editMenu = new MenuManager(
				Messages.getString("menu.submenus.edit"));
		editMenu.add(editVagonsAction);
		editMenu.add(editCompositionsAction);
		editMenu.add(editStationsAction);
		editMenu.add(editTripsAction);
		final MenuManager configMenu = new MenuManager(
				Messages.getString("menu.submenus.configuration"));
		configMenu.add(editUsersAction);
		menuBar.add(editMenu);
		menuBar.add(configMenu);
	}

}
